<?php

abstract class ResourceManager
{
    private $resources = array();
    private $data = array();
    protected $cache = null;

    public function AddResource( Resource $resource )
    {
        $this->resources[$resource->GetId()] = $resource;
    }

    public function GetResourceById( $id )
    {
        if ( isset($this->resources[$id]) )
        {
            return $this->resources[$id];
        }
        return null;
    }

    public function GetCache()
    {
        if ( is_null($this->cache) )
        {
            $this->cache = new NullCache();
        }
        return $this->cache;
    }

    public function GetData( $resourceId )
    {
        if ( isset($this->data[$resourceId]) )
        {
            return $this->data[$resourceId];
        }

        $resource = $this->GetResourceById($resourceId);
        $data = is_null($resource) ? null : $resource->GetData();
        if ( !empty($data) )
        {
            $this->data[$resourceId] = $data;
        }

        return $data;
    }
}

?>
